package com.szp.drug.component.controller;

import com.github.pagehelper.PageInfo;
import com.szp.drug.entity.DrugInstrument;
import com.szp.drug.util.ResultEntity;
import com.szp.drug.component.service.api.DrugInstrumentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 器械前端控制器
 * @author SuZePing
 * @create 2021-03-06 10:02
 * @E-mail suzeping10@126.com
 */
@Slf4j
@RestController
@RequestMapping("/instrument")
public class DrugInstrumentController {

	@Autowired
	private DrugInstrumentService instrumentService;

	/**
	 * 分页获取器械
	 * @param instrumentName
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@PostMapping("/get/page.json")
	public ResultEntity<PageInfo<DrugInstrument>> getPageInfo(
			@RequestParam(value = "instrumentName",defaultValue = "") String instrumentName,
			@RequestParam(value = "pageNum",defaultValue = "1") String pageNum,
			@RequestParam(value = "pageSize",defaultValue = "5") String pageSize
	){
		return instrumentService.getPageInfo(instrumentName, pageNum, pageSize);
	}

	/**
	 * 新增器械(并返回新增后总数量)
	 * @param instrument
	 * @return
	 */
	@PostMapping("/save.json")
	public ResultEntity<Integer> saveInstrument(DrugInstrument instrument){
		return instrumentService.saveInstrument(instrument);
	}

	/**
	 * 修改器械
	 * @param instrument
	 * @return
	 */
	@PostMapping("/edit.json")
	public ResultEntity<String> editInstrument(DrugInstrument instrument){
		return instrumentService.editInstrument(instrument);
	}

	/**
	 * 删除器械
	 * @param instrumentId
	 * @return
	 */
	@PostMapping("/del.json")
	public ResultEntity<String> removeInstrument(@RequestParam("instrumentId") String instrumentId){
		return instrumentService.removeInstrument(instrumentId);
	}
}